﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SILAS.BL;
using SILAS.Entidades;
using Microsoft.Practices.Unity;
using SILAS.UI.Models;
using SILAS.UI.ViewModels;

namespace SILAS.UI.Controllers
{
    public class DistritoController : Controller
    {
        //
        // GET: /Distrito/
        [Dependency]
        public IDistritoBL  DistritoBL{ get; set; }

        public ActionResult Index()
        {
            return View();
        }

        //********* ENCONTRAR SECTOR SELECCIONANDO UN UBIGEO *****

        public ActionResult getDistritoByUbigeo(string idubigeo)
        {

            var distrito = DistritoBL.getDistritobyUbigeo(idubigeo);

            if (distrito != null)
            {
                var msg = new
                {
                    exito = true,
                    Distrito = new
                    {
                        Id = distrito.Id,
                        lat = distrito.Ubicacion.CoorX,
                        lng = distrito.Ubicacion.CoorY,
                        altu = distrito.Ubicacion.Altura
                    }
                };

                return Json(msg, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var msg = new { exito = false, message = "No se ha seleccionado ningunn Distrito" };
                return Json(msg, JsonRequestBehavior.AllowGet);
            }




        }

        //
        // GET: /Distrito/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Distrito/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Distrito/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Distrito/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Distrito/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Distrito/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Distrito/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
